<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>异步请求案例</title>
    <script src="js/vue.js"></script>
    <script src="js/axios-0.18.0.js"></script>

</head>
<body>
<!--
    TODO: 登录之后,显示好友列表
    1. form表单的提交是同步请求
-->
<div id="div">
    <h1>登录页面</h1>

    <input type="text" name="username" placeholder="请输入用户名" v-model="user.username"> <br>
    <input type="password" name="password" placeholder="请输入密码" v-model="user.password"><br>
    <button @click="send()">登录</button>
    <button @click="send2()">转换为Json格式</button>

    <h1>主页: 显示好友列表</h1>
    <ul>
        <li v-for="person of list">
            {{person.name}}
        </li>
    </ul>
</div>

</body>
<script>
    new Vue({
        el:"#div",
        data() {
            return {
                user: {
                    username: "",
                    password: ""
                }, // 请求参数
                list: []  // 结果
            }
        },

        methods:{
            send : function () {
                //TODO:
                let url = "../Ajax2Servlet"
                let param ="username="+this.user.username+"&password="+this.user.password
                axios.post(url,param).then(response=>{
                    console.log(response.data);
                    this.list = response.data
                })
            },
            send2 : function () {
                let url = "../Ajax3Servlet"
                let param = this.user
                axios.post(url,param).then(response=>{
                    console.log(response.data);
                    this.list = response.data
                })
            }
        }
    });
</script>
</html>
<h1>我是你的</h1>